package eu.winterwheels.enterprise.controller.supply;

import java.util.List;
import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import eu.winterwheels.enterprise.model.Country;
import eu.winterwheels.enterprise.service.iso.CountryService;

//@ManagedBean
@Model
@SessionScoped
public class SupplierRegistrationController {
	@Inject
	private Logger log;

	@Inject
	private FacesContext facesContext;

	// Temporarily reference all the data from the supplier process within this controller.
	
	/** Country / Economic Area */
	@Inject
	private CountryService countryEJB;
	private Country country;
	private Country newCountry;
	/** Organisation */
	
	/** Delivery Area */
	
	/** Financial Transaction */
	
	/** Commitment */
	
	/** Verification */
	
	
	@ManagedProperty(value = "")
	private String iso2digitCountryCode;
	@ManagedProperty(value = "")
	private String countryName;
	private double vat;
	private String currency;

	// TODO put a matrix of country x province later
	private List<String> freeDeliveryCountries; // country plus province
	private List<String> chargedDeliveryCountries;

	@PostConstruct
	private void init() {
		// TODO initialize this request with the geo-IP country.
		// http://www.hostip.info/use.html
		System.out.println("MB CountryController initialized");
		// country = countryEJB.getCountryByCode(null);
		country = new Country();
		newCountry = new Country();
	}
	
	/**
	 * Return the country object.
	 * @return Country
	 */
	@Produces
	@Named
	public Country getCountry() {
		return country;
	}

	public String getIso2digitCountryCode() {
		return iso2digitCountryCode;
	}

	public void setIso2digitCountryCode(String iso2digitCountryCode) {
		this.iso2digitCountryCode = iso2digitCountryCode;
		country = countryEJB.getCountryByCode(iso2digitCountryCode);
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public CountryService getCountryLogic() {		
		return countryEJB;
	}	
}
